﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LANmine
{
    public partial class DetailsBestellingForm : Form
    {
        private Language lmLang;
        private String bestellingsnummer;

        public DetailsBestellingForm(Language lmLang, String bestellingsnummer)
        {
            this.lmLang = lmLang;
            this.bestellingsnummer = bestellingsnummer;

            InitializeComponent();
            ApplyLanguage();
            loadProduct();
        }

        #region Language Specifications
        /**
         * MainForm::ApplyLanguage()
         * ---------------------------
         * Overwrite all text properties of all elements in all forms with the right ones.
         */
        private void ApplyLanguage()
        {
            /**
             * Header label
             */
            lblProducten.Text = this.lmLang.GetString("details.lblProducten");
            /**
             * other labels & buttons
             */
            
        }
        #endregion

        private void loadProduct()
        {
            try
            {
                Database dbProducten = new Database("rw");
                SqlConnection dbConn = dbProducten.getDbConn();
                dbConn.Open();

                SqlDataAdapter daProducten = new SqlDataAdapter("Select p.naam, p.prijs From catering_producten p inner join catering_bestellingen b on p.id = b.product_id where b.bestellingsnummer = " + bestellingsnummer, dbConn);
                dbConn.Close();
                DataSet dsProducten = new DataSet("Product");

                daProducten.FillSchema(dsProducten, SchemaType.Source, "Product");
                daProducten.Fill(dsProducten, "Product");

                DataTable dtProducten;
                dtProducten = dsProducten.Tables["Product"];

                foreach (DataRow drCurrent in dtProducten.Rows)
                {
                    lbxProduct.Items.Add(drCurrent["naam"].ToString() + " " + drCurrent["prijs"].ToString());

                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
        }
    }
}
